//
//  MineCouponsVC.swift
//  LeTu
//
//  Created by g1 on 2023/12/11.
//

import UIKit

class MineCouponsVC: BaseViewController {

    private var viewModel = MineCouponsVM()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        configUI()
    }
    
    private func configUI() {
        
        navIsHidden = false
        title = "优惠券"
        
        view.addSubview(couponsSegmentedView)
        view.addSubview(listContainerView)
        
        couponsSegmentedView.snp.makeConstraints { make in
            make.left.equalTo(24)
            make.width.equalTo(screenWidth-48)
            make.top.equalToSuperview()
            make.height.equalTo(44)
        }
        listContainerView.snp.makeConstraints { make in
            make.left.bottom.equalToSuperview()
            make.width.equalTo(screenWidth)
            make.top.equalTo(couponsSegmentedView.snp.bottom)
        }
        
    }
    
    private lazy var sliderView: JXSegmentedIndicatorGradientLineView = {//标题背景
        let sliderView = JXSegmentedIndicatorGradientLineView()
        sliderView.colors =  [UIColor(red: 1, green: 0.839, blue: 0, alpha: 1), UIColor(red: 0.851, green: 0.851, blue: 0.851, alpha: 0)]
        return sliderView
    }()
    lazy var dataSource: JXSegmentedTitleDataSource = {
        let ds = JXSegmentedTitleDataSource()
        ds.titles = viewModel.titles
        ds.titleNormalColor =  .app_textGrayColor
        ds.titleSelectedColor = .app_black
        ds.titleNormalFont = kSetPingFangMedium(14)
        ds.titleSelectedFont = kSetPingFangMedium(14)
        ds.itemSpacing = 0
        return ds
    }()
    lazy var listContainerView: JXSegmentedListContainerView = {
        let lv = JXSegmentedListContainerView(dataSource: self)
        lv.backgroundColor = .app_viewBackgroundColor
        return lv
    }()
    private(set) lazy var couponsSegmentedView: JXSegmentedView = {
        let sv = JXSegmentedView(frame: CGRect.zero)
        sv.backgroundColor = .app_white
        sv.dataSource = dataSource //数据源
        sv.indicators = [sliderView] //标题下的横线
        sv.listContainer = listContainerView //视图容器
        sv.contentEdgeInsetLeft = 0
        sv.contentEdgeInsetRight = 0
        sv.delegate = self //设置代理
        return sv
    }()

}

extension MineCouponsVC : JXSegmentedListContainerViewDataSource {
    
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        return viewModel.titles.count
    }
    
    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        let listView = MineCouponsContainerView()
        listView.setIndex(index)
        return listView
    }
}

extension MineCouponsVC : JXSegmentedViewDelegate {
    
    func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
        
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, didClickSelectedItemAt index: Int) {
        
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, didScrollSelectedItemAt index: Int) {
        
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, scrollingFrom leftIndex: Int, to rightIndex: Int, percent: CGFloat) {
        
    }
    
    func segmentedView(_ segmentedView: JXSegmentedView, canClickItemAt index: Int) -> Bool {
        return true
    }
}



